package chapter15;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by lzy
 * Date: 2018/5/13
 */
public class CheckedList {
    @SuppressWarnings("unchecked")
    static void oldStyleMethod(List probablyDogs) {
        probablyDogs.add(new Cat());
    }

    public static void main(String[] args) {
        List<Dog> dogs = new ArrayList<>();
        oldStyleMethod(dogs);
        List<Dog> dogs2 = Collections.checkedList(new ArrayList<Dog>(), Dog.class);
        try {
            oldStyleMethod(dogs2);
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }
}
